/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
 */
Ext.ns('net.autodata.modelwalk');
(function () {
	
	/**
	 * This view defines a layout (for the ModelWalkPanel) to be used within Ext.Button Menus
	 * @class ModelWalkMenuView
	 * @extends net.autodata.modelwalk.ModelWalkView
	 * @namespace net.autodata.modelwalk
	 */
	var View = Ext.extend(net.autodata.modelwalk.ModelWalkView, {
		
		cls: 'modelwalk-menu-view',
		
		/**
		 * @method init
		 */
		init: function ()
		{
			View.superclass.init.apply(this, arguments);
		},
		
		/**
		 * @method initTemplates
		 */
		initTemplates: function ()
		{
			var tpls = this.templates || {};
						
			if (tpls.mainTpl === undefined) {
				tpls.mainTpl = new Ext.Template(
					'<div class="modelwalk-view {viewCls}">',
						'<div class="modelwalk-header"><h5>' + ASC.message('net.autodata.modelwalk.label.select-a-vehicle') + '</h5></div>',
						'<div class="modelwalk-body">',
							'<div class="first-item wrap modelyear-wrap"></div>',
							'<div class="wrap make-wrap"></div>',
							'<div class="wrap model-wrap"></div>',
							'<div class="last-item wrap trim-wrap"></div>',
						'</div>',
					'</div>',
					{
						compiled: true,
						disableFormats: true
				});
			}
			
			this.templates = tpls;
			
			View.superclass.initTemplates.apply(this, arguments);			
		},
		
		
		/**
		 * Adds a implementation of getListParent to each ComboBox within the ModelWalkPanel
		 * to prevent the menu from closing when the user is interacting witht the ComboBox
		 * @method render
		 */
		render: function ()
		{
			//Change the empty text first
			var mw = this.component;
						
			mw.modelYear.emptyText = ASC.message('net.autodata.modelwalk.modelYear');
			mw.make.emptyText = ASC.message('net.autodata.modelwalk.make');
			mw.model.emptyText = ASC.message('net.autodata.modelwalk.model');
			mw.trim.emptyText = ASC.message('net.autodata.modelwalk.trim');
			
			var getListParent = function() { return this.el.up('.x-menu'); };
			
			Ext.iterate(mw.dependencyMap, function (p, v) {
				var combo = mw[p];
				if (!combo instanceof Ext.form.ComboBox) {
					return;
				}
				combo.getListParent = getListParent;
				
			}, this);
		
			
			View.superclass.render.apply(this, arguments);
						
		}
	});
	
	net.autodata.modelwalk.ModelWalkMenuView = View;
})();